package service

import (
	"advertising/internal/dao"
	"advertising/internal/models"
	"context"

	"gorm.io/gorm"
)

type SupportActivityService struct{}

// Create 创建支持活动
func (SupportActivityService) Create(ctx context.Context, db *gorm.DB, name string, startTime, endTime int64, materialIDs, userID, username string) (id string, err error) {
	return dao.SupportActivity{}.Create(ctx, db, name, startTime, endTime, materialIDs, userID, username)
}

// Update 更新支持活动
func (SupportActivityService) Update(ctx context.Context, db *gorm.DB, id, name string, startTime, endTime int64, materialIDs string) error {
	return dao.SupportActivity{}.Update(ctx, db, id, name, startTime, endTime, materialIDs)
}

// Delete 删除支持活动
func (SupportActivityService) Delete(ctx context.Context, db *gorm.DB, id string) error {
	return dao.SupportActivity{}.Delete(ctx, db, id)
}

// Detail 获取活动详情
func (SupportActivityService) Detail(ctx context.Context, db *gorm.DB, id string) (*models.SupportActivity, error) {
	return dao.SupportActivity{}.Detail(ctx, db, id)
}

// List 获取支持活动列表
func (SupportActivityService) List(ctx context.Context, db *gorm.DB, name, id string, status int8, createUser string, startTime, endTime int64, page, limit int) ([]*models.SupportActivity, int64, error) {
	return dao.SupportActivity{}.List(ctx, db, name, id, status, createUser, startTime, endTime, page, limit)
}

// ChangeStatus 修改活动状态
func (SupportActivityService) ChangeStatus(ctx context.Context, db *gorm.DB, id string, status int8) error {
	return dao.SupportActivity{}.ChangeStatus(ctx, db, id, status)
}

// SameNameExist 检查同名活动是否存在
func (SupportActivityService) SameNameExist(ctx context.Context, db *gorm.DB, name, exceptID string) int64 {
	return dao.SupportActivity{}.SameNameExist(ctx, db, name, exceptID)
}

// GetActivityListByMaterialIDs 根据素材ID获取关联的活动列表
func (SupportActivityService) GetActivityListByMaterialIDs(ctx context.Context, db *gorm.DB, materialID string) ([]*models.SupportActivity, error) {
	return dao.SupportActivity{}.GetActivityListByMaterialIDs(ctx, db, materialID)
}

// GetMaterialIDsList 获取活动关联的素材ID列表
func (SupportActivityService) GetMaterialIDsList(ctx context.Context, db *gorm.DB, ids []string) ([]struct {
	ID          string `json:"id"`
	MaterialIDs string `json:"material_ids"`
}, error) {
	return dao.SupportActivity{}.GetMaterialIDsList(ctx, db, ids)
}

// SetMaterialIDs 更新活动素材 ID
func (SupportActivityService) SetMaterialIDs(ctx context.Context, db *gorm.DB, id, materialIDs string) error {
	return dao.SupportActivity{}.SetMaterialIDs(ctx, db, id, materialIDs)
}
